<?php
/**
 * Created by PhpStorm.
 * @description:
 * @time:
 * @Author: yfl
 * @QQ 554665488
 * Date: 2018-5-26
 * Time: 19:55
 */
//向客户端发送消息
$msg_server = new swoole_server('127.0.0.1', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$msg_server->set([
    'worker_num' => 2
]);
$msg_server->on('WorkerStart', function ($serv, $worker_id) {
//       var_dump($worker_id);
//    var_dump($serv->connection_list());
    if ($worker_id == 0) {
        $serv->after(10000, function () use ($serv) {
            foreach ($serv->connection_list() as $fd) {
                $serv->send($fd,$fd.'来了');
           }
        });
    }

});
$msg_server->on('connect', function ($serv, $fd) {

    echo $fd . '参与活动' . PHP_EOL;
});
$msg_server->on('receive', function ($srev, $fd, $from_id, $data) {

});
$msg_server->on('close', function ($serv, $fd) {
    echo "编号为{$fd}的客户端已经关闭." . PHP_EOL;
});
$msg_server->start();